<template>
	<view class="container">
		<view class="top-banner">
			<view class="userInfo">
				<view class="head-img">
					<image :src="userInfo.photo" @click="uploadFile"></image>
				</view>
				<view class="userName">
					<view class="name">{{userInfo.userName}}</view>
					<view class="text">asdfasdf</view>
				</view>
			</view>
			<view class="tag-menu">
				<view class="tag-item">女</view>
				<view class="tag-item">+添加生日、地区标签</view>
			</view>
			<view class="statistics">
				<view class="menu-list">
					<view class="menu-list-item" v-for="item in menuList">
						<view class="num">{{item.num}}</view>
						<view class="text">{{item.text}}</view>
					</view>
				</view>
				<view class="editBtn">编辑资料</view>
			</view>
		</view>
		<view class="content">
			<view class="content-head">
				<view :class="['content-head-item',{active:index==currentIndex}]"
					v-for="(item,index) in contentHeadList" @click="change(index)">
					{{item.title}}
				</view>
			</view>
			<view class="content-info">
				<view class="content-info-item"></view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userToken: "",
				userInfo: {
					userName: '用户昵称',
					photo: require("../../static/image/qq.png")
				},
				menuList: [{
					num: 0,
					text: '关注'
				}, {
					num: 0,
					text: '粉丝'
				}],
				contentHeadList: [{
					title: '微记',
				}, {
					title: '收藏',
				}, {
					title: '赞过',
				}],
				currentIndex: 0
			}
		},
		onLoad() {
			this.getUserInfo()
		},
		methods: {
			getUserInfo() {
				this.userToken = uni.getStorageSync('token')
				console.log(this.userToken)
				uni.request({
					header: {
						"Authorization": this.userToken
					},
					url: 'http://microtourism.natapp1.cc/api-user/users',
					method: 'GET',
					success: (res) => {

						console.log(JSON.stringify(res.data.data))
						var user = res.data.data
						this.userInfo.userName = user.userName
						this.userInfo.photo = user.avatar
						uni.showToast({
							title: '欢迎回来: '+this.userInfo.userName,
							icon:"none",
							duration: 2000
						});
					}
				})
			},
			change(index) {

				this.currentIndex = index
			},
			uploadFile() {
				let that = this
				uni.chooseImage({
					// count:  允许上传的照片数量
					count: 5,
					// sizeType:  original 原图，compressed 压缩图，默认二者都有
					sizeType: "original",
					success: (res) => {
						that.userInfo.photo = res.tempFilePaths[0]
					}
				});
			}
		}
	}
</script>

<style>
	@import "./cen.css";
</style>
